<template>
    <div class="acceptance-registration-pages">
        <commpVxeTable
         :config="dataTableConfig" 
         :columns="columnsVxe" 
         :formItem="formItem"
         @checkboxChange="checkboxChange"
         ref="acceptanceRegistrationRef"
         >
            <template v-slot:externalOperations="{data}"  >
                <vxe-form-item >
                    <template>
                        <div class="select-date-box">
                            <a-date-picker  @change="specifyDateChange" placeholder="请选择指定日期"/>
                        </div>
                    </template>
                </vxe-form-item>
                <vxe-form-item>
                    <template>
                        <a-button class="blue-btn" type="primary" @click="specifyDateClick(0)">获取指定日期</a-button>
                    </template>
                </vxe-form-item>
                <vxe-form-item>
                    <template>
                        <a-button class="blue-btn" type="primary" @click="specifyDateClick(1)">获取当日</a-button>
                    </template>
                </vxe-form-item>
                <vxe-form-item>
                    <template>
                        <a-button class="blue-btn" type="primary" @click="addition()">新增</a-button>
                    </template>
                </vxe-form-item>
                <vxe-form-item>
                    <template>
                        <a-button class="blue-btn" type="primary" @click="batchClick()">批量办理</a-button>
                    </template>
                </vxe-form-item>
                <vxe-form-item>
                    <template>
                        <a-button class="blue-btn" type="primary" @click="batchDeletion()">批量删除</a-button>
                    </template>
                </vxe-form-item>
            </template>
            <template v-slot:fsxmc_name="{row}" data-desc="自定操作栏">
                <span v-if="row.fzwxtbzzt == '补正中'" class="fsxmcQ-c-t">[{{ row.fzwxtbzzt}}]</span>
                <span v-if="row.fzwxtbzzt == '已补正'" class="fsxmcQ-l-t">[{{ row.fzwxtbzzt}}]</span>

                <span v-if="row.fzwxtzgzt == '整改中'" class="fsxmcQ-c-t">[{{ row.fzwxtzgzt }}]</span>
                <span v-if="row.fzwxtzgzt == '已整改'" class="fsxmcQ-l-t">[{{ row.fzwxtzgzt }}]</span>

                <span v-if="row.fzwxtcjzt == '撤件回复'" class="fsxmcQ-h-t" @click="cjhfClick()">[{{ row.fzwxtcjzt }}]</span>
                <span v-if="row.fzwxtcjzt == '撤件审核中'" class="fsxmcQ-c-t">[{{ row.fzwxtcjzt }}]</span>
                <span v-if="row.fzwxtcjzt == '已撤件'" class="fsxmcQ-l-t">[{{ row.fzwxtcjzt }}]</span>

                <span v-if="row.fzwxtthzt" class="fsxmcQ-h-t">{{ row.fzwxtthzt }}</span>
                <span>{{ row.fsxmc }}</span>
            </template>
            <template v-slot:name_fslsj="{row}" data-desc="自定操作栏">
                <span>{{ timeProcessing(row.fslsj) }}</span>
            </template>
            <template v-slot:operation_btn="{row}" data-desc="自定操作栏">
                <a-form layout="inline" class="search-form" >
                    <a-form-item >
                        <a-button class="blue-btn" type="primary" @click="reviseClick(row)">办理</a-button>
                    </a-form-item>
                    <a-form-item >
                        <a-button class="red-btn" type="primary" @click="duplicate(row)" >复制</a-button>
                    </a-form-item>
                </a-form>
            </template>
        </commpVxeTable>
        <a-modal v-model="numFigureVisible" title="复制" @ok="numFigureOk">
            <div style="width: 100%;" class="modal-btn-box">
                <a-form :label-col="{ span: 12 }" :wrapper-col="{ span: 12 }" layout="inline">
                    <a-form-item label="复制个数">
                        <a-input-number id="inputNumber" v-model="numFigure" :min="1" @change="numFigureChange" />
                    </a-form-item>
                </a-form>
            </div>
        </a-modal>
        <increase ref="refModel" :addEditParameter="addEditParameter" @successReturn="successReturn" @reviseClick="reviseClick"/>
        <batchProcessing ref="batchProcessingRef" @successReturn="successReturn" />
    </div>
</template>
<script>
import {typeInput, typeNumber, typeSelect, typeCheckbox, typeRadio} from '@/components/compSearchCriteria/ContractType'
import assessCheckApi from './service/api.js'
import increase from './increase.vue'
import batchProcessing from './batchProcessing.vue'
import { 
    deleteArrServe, 
    ocalityPostAction, 
    dateDataServe, 
    duplicateServe, 
    queryJobByJobIdServe, 
    getDictListByDictCodeServe,
    getSqsxBm,
 } from './service/index'
import commpVxeTable from '@/components/commp-vxe-table/commp-vxe-table.vue'
import moment from 'moment'
import blobType from '@/common/blobType'
  export default {
    components:{
        increase,
        commpVxeTable,
        batchProcessing,
    },
    
    data(){
        return{
            routeName:this.$route.name,
            addEditParameter:{},
            formItem:[
                {
                    label: '事项名称',
                    model: 'fsxmc',
                },{
                    label: '企业名称',
                    model: 'fqymc',
                },{
                    label: '申请单号',
                    model: 'fsqdbh',
                },{
                    label: '任务编号',
                    model: 'fslbh',
                }

            ],
                // {
                //     label: '所在地市',
                //     model: 'fszds',
                //     placeholder: '所在地市',
                //     type:typeSelect,
                //     dictionaryType:'观察员所属地市',
                //     selectArr:this.dictionaryQuery('观察员所属地市')
                // }
            columnsVxe:[{ type: 'checkbox', width: 60 ,fixed: 'left',},{
                    title: '事项名称', //列头显示文字
                    field: 'fsxmc',
                slots: {
                    default: 'fsxmc_name',
                },
                    fixed: 'left',
                },{
                    title: '企业名称', //列头显示文字
                    field: 'fqymc',
                },{
                    title: '申请单号',
                    field: 'fsqdbh',
                },{
                    title: '任务编号',
                    field: 'fslbh',
                },{
                    title: '接收时间',
                    field: 'fslsj',
                    slots: {
                        // 使用插槽模板渲染
                        default: 'name_fslsj',
                    },
                },{
                    title: '剩余天数',
                    field: 'syday',
                },{
                    title: '任务类型',
                    field: 'frwlx',
                },{
                    title: '操作',
                    field: 'jobid',
                    slots: {
                    // 使用插槽模板渲染
                    default: 'operation_btn',
                  },
                    fixed: 'right',
                    width:200,
                }],
            dataTableConfig:{
                api: assessCheckApi.list,
                rowId: 'jobid',
                fywflcode:blobType.fywflcodeArr[blobType.menuType.indexOf(this.$route.name.substring(this.$route.name.indexOf('__'),this.$route.name.indexOf('_a')+2))],
                paramet:{
                    fhjmc:'任务受理',
                    fblzt:'待办'
                }
            },
            specifyDateVal:'',
            isSpecifyDate:false,
            numFigure:1,
            numFigureVisible:false,
            currentReplicationId:'',
            selectedRowKeysArr:[],
        }
    },
    
    methods:{
        cjhfClick(){
            this.$route.push('/enterpriseWithdrawalApplication/index')
        },
        timeProcessing(val){
            if(val){
                val = val.slice(0,11)
            }
            return val
        },
        async dictionaryQuery(val){
            let dataObj = []
            await ocalityPostAction({dictName:val}).then(res=>{
                //console.log('字典的res',res)
                if(res.code == 200){
                    if(res.result.length){
                        dataObj = res.result
                    }
                    
                }
            })
            return dataObj
        },
        checkboxChange(val){//获取当前选择的行
            //console.log('当前选择表格',val)
            this.selectedRowKeysArr = []
            val.forEach(item => {
                this.selectedRowKeysArr.push(item.jobid)
            });
            //console.log(this.selectedRowKeysArr)
        },
        specifyDateClick(val){
            if(val){
                //console.log('3',moment(new Date()).format('YYYY-MM-DD'))
                this.accessDateDataServe(moment(new Date()).format('YYYY-MM-DD'))
            }else{
                //console.log('1',this.specifyDateVal)
                if(this.specifyDateVal){
                    this.accessDateDataServe(this.specifyDateVal)
                }else{
                    this.$message.warning('请选择日期')
                }
                this.$forceUpdate()
            }
        },
        accessDateDataServe(val){
            //console.log('2',val)
            dateDataServe({time:val+" 00:00:00"}).then(res=>{
                if(res.code == 200){
                    this.$message.success('获取成功')
                    this.$refs.acceptanceRegistrationRef.searchEvent()
                }
            })
        },
        specifyDateChange(val){
            //console.log(moment(val).format('YYYY-MM-DD'))
            this.specifyDateVal = moment(val).format('YYYY-MM-DD')
        },
        addition(){//新增
            let itemValue = ''
            getDictListByDictCodeServe({dictCode:'jclx'+blobType.fywflcodeArr[blobType.menuType.indexOf(this.routeName.substr(this.routeName.indexOf('__'),this.routeName.indexOf('_a')+1))]}).then(res=>{
                itemValue = res.result[0].itemValue
                this.$refs.refModel.visibleShow = true
                this.$refs.refModel.spinning = true
                this.$aSpinningKey = true
                this.addEditParameter = {
                    fywflcode:blobType.fywflcodeArr[blobType.menuType.indexOf(this.$route.name.substring(this.$route.name.indexOf('__'),this.$route.name.indexOf('_a')+2))],
                    jobid:'',
                    sqsxid:'',
                    fsxmc:'',
                    fsqsj:moment(new Date()).format('YYYY-MM-DD'),
                    fjclx:itemValue,
                    fslzt:'1',
                    fslsj:moment(new Date()).format('YYYY-MM-DD'),
                    fslbh:'',
                    fwcsx:'',
                    fjzrq:'',

                    fqyid:'',//企业Id
                    fqymc:'',
                    ftyshxydm:'',
                    fqyfddbrfzr:'',
                    fqylxr:'',
                    fqylxrdh:'',
                    fqyzszcdz:'',
                    fszdq:'南宁',
                    fxxdz:'',

                    fcpmc:'',//产品名称
                    fsqdbh:'',
                    fspdwmc:'',
                    fbldwmc:'',
                    ffsr:'',
                    ffssj:'',
                    fblr:'',
                    dbrid:[],
                    opinion:'',//办理意见
                    smgflag:false,//是否发送短信
                    fthyj:'',
                    fblzt:'',
                    isOwn:true,
                }
                this.$refs.refModel.getData(this.addEditParameter)
            })
            
        },
        successReturn(){
            this.$refs.acceptanceRegistrationRef.searchEvent()
        },
        batchDeletion(){//
            var that = this
            this.$confirm({
                title:'您确认要删除吗？',
                // icon: createVNode(ExclamationCircleOutlined),
                onOk() {
                    if(that.selectedRowKeysArr.length){
                        let deleteString = that.selectedRowKeysArr.join(',')
                        deleteArrServe({jobids:deleteString}).then(res=>{
                            if(res.code == 200){
                                that.$message.success('删除成功')
                            }else{
                                that.$message.warning(res.message)
                            }              
                            that.$refs.acceptanceRegistrationRef.searchEvent()
                        })
                    }else{
                        that.$message.warning('请选择删除项')
                    }
                },
                
            });
            
            
        },
        //批量办理
        batchClick(){
            if(this.selectedRowKeysArr.length){
                this.$refs.batchProcessingRef.batchProcessingVisible = true
                this.$refs.batchProcessingRef.getData(this.selectedRowKeysArr.join(','))
            }else{
                this.$message.warning('请选择批量办理项')
            }
            
        },
        handleOk(val,id){
            if(val && !id){
                this.$refs.acceptanceRegistrationRef.resetEvent()
            }else if(val && id){
                this.requestParams = {
                    ...this.requestParams,
                    renovate:true,
                }
            }
            
        },
        duplicate(val){//复制
            this.numFigureVisible = true
            this.currentReplicationId = val.sqsxid
        },
        //
        numFigureChange(val){//复制个数的弹窗
            if(!val){
                this.numFigure = 1
            }
        },
        numFigureOk(){//保存复制
            duplicateServe({sqsxid:this.currentReplicationId,number:this.numFigure}).then(res=>{
                if(res.code == 200){
                    this.$message.success('复制成功')
                    this.$refs.acceptanceRegistrationRef.searchEvent()
                    this.numFigureVisible = false
                    this.numFigure = 1
                }else{
                    this.$message.warning(res.message)
                }
            })
        },
        //编辑
        reviseClick(val){
            queryJobByJobIdServe({jobid:val.jobid}).then(res=>{
                //console.log(res)
                if(res.code == 200){
                    let data = res.result.sqsx
                    // getSqsxBm({sqsxid:data.id}).then(res2=>{
                    //     if(res2.code == 200){
                            this.addEditParameter = {
                                // sqsxbm:res2.result,
                                fywflcode:blobType.fywflcodeArr[blobType.menuType.indexOf(this.$route.name.substring(this.$route.name.indexOf('__'),this.$route.name.indexOf('_a')+2))],
                                jobid:res.result.job.id,
                                fblzt:res.result.job.fblzt,
                                fthyj:res.result.job.fthyj,
                                nextNodeDbrList:res.result.nextNodeDbrList,
                                nextNode:res.result.nextNode,
                                sqsxid:data.id,
                                fsxmc:data.fsxmc,
                                fsqsj:data.fsqsj?moment(data.fsqsj).format('YYYY-MM-DD'):'',
                                fjclx:data.fjclx,
                                fslzt:String(data.fslzt),
                                fslsj:data.fslsj?moment(data.fslsj).format('YYYY-MM-DD'):'',
                                fslbh:data.fslbh,
                                fyzbm:data.fyzbm,
                                fpzwh:data.fpzwh,
                                fcpgg:data.fcpgg,
                                fwcsx:data.fwcsx,
                                fjzrq:data.fjzrq,

                                fqyid:data.fqyid,//企业Id
                                fqymc:data.fqymc,
                                ftyshxydm:data.ftyshxydm,
                                fqyfddbrfzr:data.fqyfddbrfzr,
                                fqylxr:data.fqylxr,
                                fqylxrdh:data.fqylxrdh,
                                fqyzszcdz:data.fqyzszcdz,
                                fszdq:data.fszdq,
                                fxxdz:data.fxxdz,

                                fcpmc:data.fcpmc,//产品名称
                                fsqdbh:data.fsqdbh,
                                fspdwmc:data.fspdwmc,
                                fbldwmc:data.fbldwmc,
                                ffsr:data.ffsr,
                                ffssj:data.ffssj,
                                fblr:data.fblr,
                                dbrid:[],
                                opinion:'',//办理意见
                                smgflag:false,//是否发送短信
                                isOwn:true,
                                fjcdz:data.fjcdz,
                                fjbrmc:data.fjbrmc,
                                fxcjc:data.fxcjc,
                                fjx:data.fjx,
                                frwhmc:data.frwhmc,
                                frwhh:data.frwhh,
                                ...res.result.qy,
                            }
                            this.$refs.refModel.visibleShow = true
                            this.$refs.refModel.spinning = true
                            this.$aSpinningKey = true
                            this.$refs.refModel.getData(this.addEditParameter)
                    //     }else{
                    //         this.$message.warning(res2.message)
                    //     }
                    // })
                }else{
                    this.$message.warning(res.message)
                }
            })
            
            
        },
        
        AddHandleOk(){
            this.$refs.acceptanceRegistrationRef.resetEvent()
        },
    },

  }
</script>
<style lang="less">
.acceptance-registration-pages{
    .select-date-box{
        display: flex;
        flex-direction: column;
        span{
            color: #f5222d;
            font-size: 14px;
        }
    }
    .modal-btn-box{
        .ant-form-item-control{
            width: 175px !important;
        }
    }
    
}
</style>
<style scoped >
.observer-lbrary-pages{
    background: #fff;
}
.btn-box{
    display: flex;
    justify-content: flex-end;
}
.blue-btn{
    border: 1px solid #5ca3e5 !important;
    background-color: #5ca3e5 !important;
    color: #fff !important;
}
.red-btn{
    border: 1px solid #ed5565 !important;
    background-color: #ed5565 !important;
}




</style>